//
//  YYEMainViewController.swift
//  weibo14
//
//  Created by mac on 16/3/2.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class YYEMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let vc = YYETabBar()
        
        // 回调点击事件
        vc.callBack = { [weak self] in
        
            print("按了按钮",NSThread.currentThread())
            
            let composeView = YYECompose()
//            self!.view.addSubview(composeView)
            composeView.show(self!)
            
            
        }
        
        // 利用KVC对只读的属性赋值
        self.setValue(vc, forKeyPath: "tabBar")
        
        // 添加四个导航控制器
      
        addChildViewController(YYEHomeViewController(), imageNamed: "tabbar_home", title: "首页")
        
        addChildViewController(YYEMessageViewController(), imageNamed: "tabbar_message_center", title: "消息")
        
        addChildViewController(YYEDiscoverViewController(), imageNamed: "tabbar_discover", title: "发现")
        
        addChildViewController(YYEPrifileViewController(), imageNamed: "tabbar_profile",
            title: "我")
        
    }
    
    private func addChildViewController(childController: UIViewController, imageNamed: String, title: String) {
    
        childController.tabBarItem = YYETabBarItem()
        
        // 设置标题
        // childController.tabBarItem.title = title
        childController.title = title
        
        childController.tabBarItem.image = UIImage(named: imageNamed)?.imageWithRenderingMode(.AlwaysOriginal)
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageNamed)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        // 设置字的颜色
        let atr = [NSForegroundColorAttributeName:UIColor.orangeColor()]
        
        childController.tabBarItem.setTitleTextAttributes(atr, forState: UIControlState.Selected)
        
        addChildViewController(YYENavigationController(rootViewController:childController))
        
        
    }


}
